package com.thread.plbc;

/**
 * @author げっしょく
 * @date 2021/8/5
 */
public class TicketOffice {
    private int ticket;

    public TicketOffice(int ticket) {
        this.ticket = ticket;
    }

    public TicketOffice() {
    }

    public int getTicket() {
        return ticket;
    }

    public void setTicket(int ticket) {
        this.ticket = ticket;
    }
    public synchronized void BuyTicket(){
        if(this.getTicket() == 0){
            System.out.println(Thread.currentThread().getName() + "窗口购票失败，当前没有余票"  );
            return;
        }
        ticket--;
        System.out.println(Thread.currentThread().getName() + "窗口成功购票一张"  );
        System.out.println("现在余票有：" + this.getTicket());
    }
}
